﻿/*----------------------------------------------------------------
           // Copyright (C) 2008 安华顺通(北京)科技有限公司
           // 版权所有。 
           //
           // 文件名：ExtendDataType.cs
           // 文件功能描述：扩展数据类型。
           //
           // 
           // 创建标识：丁余良 20080927
           //
           // 修改标识
           // 修改描述：
           //
           // 修改标识：
           // 修改描述：
----------------------------------------------------------------*/

using System;
using System.Collections.Generic;
using System.Text;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Drawing;
using System.Text.RegularExpressions;
using RuleCode.ObjectTree;

namespace RuleCode.Common
{


    public class ExtendDataType : Object, IBaseInterface
    {

        public virtual void SetValue(object value) { }
        public virtual object ObjectValue { get; set; }
        public virtual string StringValue { get; set; }
        public virtual System.Type ValueType { get; set; }
        public virtual System.Type ExtendType { get; set; }


        private string label;
        /// <summary>
        /// 多语言显示 
        /// </summary>
        public string ZLabel
        {
            get { return this.label; }
            set { this.label = value; }
        }

        /// <summary>
        /// 扩展数据类型在对象树中的属性集合
        /// </summary>
        public virtual RuleCode.ObjectTree.EDTProperty BaseProperty { get; set; }
        public virtual List<EDTRelation> Relations { get; set; }
        public virtual ExtendDataType  GetDefautValue() { return null; }


    }

    /// <summary>
    /// 数据类型为enum
    /// </summary>
    public class EEnum : ExtendDataType
    {

        public static readonly EEnum  DefaultValue =new EEnum ( 0);
        public static explicit operator bool(EEnum x) { return x.Value == DefaultValue.Value ; }


        private int value;
        public EEnum() { this.value = DefaultValue.Value; }
        public EEnum(int val) { this.value = val; }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return SystemLanguage.Instance.GetLabel(this.enumatorProperty[this.value].Label); }

        #region 属性
        public int Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.StringValue; } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region
        public override System.Type ValueType { get { return typeof(int); } }
        public override object ObjectValue { get { return this.value; } set { this.value = Convert.ToInt32(value); } }
        public override string StringValue
        {
            get { return this.value.ToString(); }
            set
            {
                this.value = Convert.ToInt32(value);
            }
        }
        #endregion

        #region EEnum和int之间的显式转换
        public static implicit operator EEnum(int x) { return new EEnum(x); }
        public static explicit operator int(EEnum x) { return x.Value; }
        #endregion

        #region 运算符


        //EEnum.Null可以和其他EEnum 对象比较操作==,!=；
        public static bool operator ==(EEnum x, EEnum y) { return x.value == y.value; }
        public static bool operator !=(EEnum x, EEnum y) { return x.value != y.value; }
        #endregion

        public override void SetValue(object value)
        {
            if (value == null)
                value = DefaultValue.Value;
            this.value = Convert.ToInt32(value);

        }



        protected RuleCode.ObjectTree.EDTEnumProperty property;
        /// <summary>
        /// 表字段在对象树中的 属性列表
        /// </summary>
        public virtual EDTEnumProperty Property { get; set; }
        public override RuleCode.ObjectTree.EDTProperty BaseProperty
        {
            get { return this.Property; } 
        }

        public override ExtendDataType  GetDefautValue()
        {
            return DefaultValue;
        }

        protected List<EnumatorProperty> enumatorProperty;
        public virtual List<EnumatorProperty> EnumatorProperty { get; set; }
        private System.Type baseEnumType;
        public System.Type BaseEnumType
        {
            get { return this.baseEnumType; }
            set { this.baseEnumType = value; }
        }
    }



    /// <summary>
    /// EInt 类的数据类型为int
    /// </summary>
    public class EInt : ExtendDataType
    {
        private int value;
        public static readonly EInt  DefaultValue = new EInt (0);
        public static explicit operator bool(EInt x) { return x.Value == DefaultValue.Value; }



        public EInt() { this.value = DefaultValue.Value; }
        public EInt(int val) { this.value = val; }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        #region 属性

        public int Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region
        public override System.Type ValueType { get { return typeof(int); } }
        public override object ObjectValue { get { return this.value; } set { this.value = (int)value; } }
        public override string StringValue
        {
            get { return this.value.ToString(); }
            set { this.value = Convert.ToInt32(value); }
        }
        #endregion

        #region EInt和int之间的显式转换
        public static implicit operator EInt(int x) { return new EInt(x); }
        public static explicit operator int(EInt x) { return x.Value; }
        #endregion

        #region 运算符
        public static EInt operator +(EInt x) { return x; }
        public static EInt operator -(EInt x) { return (new EInt(-x.value)); }

        public static EInt operator +(EInt x, EInt y) { return new EInt(x.value + y.value); }
        public static EInt operator -(EInt x, EInt y) { return new EInt(x.value - y.value); }
        public static EInt operator *(EInt x, EInt y) { return new EInt(x.value * y.value); }
        public static EInt operator /(EInt x, EInt y) { return new EInt(x.value / y.value); }
        public static EInt operator %(EInt x, EInt y) { return new EInt(x.value % y.value); }


        //EInt.Null可以和其他EInt 对象比较操作==,!=；
        public static bool operator ==(EInt x, EInt y) { return (x.value == y.value); }
        public static bool operator !=(EInt x, EInt y) { return (x.value != y.value); }
        public static bool operator >(EInt x, EInt y) { return (x.value > y.value); }
        public static bool operator <(EInt x, EInt y) { return (x.value < y.value); }
        public static bool operator >=(EInt x, EInt y) { return (x.value >= y.value); }
        public static bool operator <=(EInt x, EInt y) { return (x.value <= y.value); }
        #endregion

        public override void SetValue(object value)
        {
            if (value == null)
                value = DefaultValue.Value;
            this.value = Convert.ToInt32(value);

        }

        protected EDTIntProperty property;
        public virtual EDTIntProperty Property { get; set; }
        public override EDTProperty BaseProperty
        {
            get
            {
                return this.Property;
            }
        }
        public override ExtendDataType  GetDefautValue()
        {
            return DefaultValue;

        }

    }


    /// <summary>
    /// EInt64 数据类型
    /// </summary>
    public class EInt64 : ExtendDataType
    {
        private Int64 value;

        public static readonly EInt64 DefaultValue =new EInt64 ( 0);
        public static explicit operator bool(EInt64 x) { return x.Value == DefaultValue.Value; }



        public EInt64() { this.value = DefaultValue.Value; }
        public EInt64(Int64 value) { this.value = value; }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        #region 属性

        public Int64 Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region EInt64和Int64之间的显式转换
        public static implicit operator EInt64(Int64 x) { return new EInt64(x); }
        public static explicit operator Int64(EInt64 x) { return x.Value; }
        #endregion

        #region 运算符
        public static EInt64 operator +(EInt64 x) { return x; }
        public static EInt64 operator -(EInt64 x) { return (new EInt64(-x.value)); }

        public static EInt64 operator +(EInt64 x, EInt64 y) { return new EInt64(x.value + y.value); }
        public static EInt64 operator -(EInt64 x, EInt64 y) { return new EInt64(x.value - y.value); }
        public static EInt64 operator *(EInt64 x, EInt64 y) { return new EInt64(x.value * y.value); }
        public static EInt64 operator /(EInt64 x, EInt64 y) { return new EInt64(x.value / y.value); }
        public static EInt64 operator %(EInt64 x, EInt64 y) { return new EInt64(x.value % y.value); }


        //EInt.Null可以和其他EInt 对象比较操作==,!=；
        public static bool operator ==(EInt64 x, EInt64 y) { return (x.value == y.value); }
        public static bool operator !=(EInt64 x, EInt64 y) { return (x.value != y.value); }
        public static bool operator >(EInt64 x, EInt64 y) { return (x.value > y.value); }
        public static bool operator <(EInt64 x, EInt64 y) { return (x.value < y.value); }
        public static bool operator >=(EInt64 x, EInt64 y) { return (x.value >= y.value); }
        public static bool operator <=(EInt64 x, EInt64 y) { return (x.value <= y.value); }
        #endregion


        #region
        public override System.Type ValueType { get { return typeof(Int64); } }
        public override object ObjectValue { get { return this.value; } set { this.value = (Int64)value; } }
        public override string StringValue
        {
            get { return this.value.ToString(); }
            set { this.value = Convert.ToInt64(value); }
        }
        #endregion

        public override void SetValue(object value)
        {
            if (value == null)
                value = DefaultValue.Value;
            this.value = Convert.ToInt64(value);
        }
        public override ExtendDataType  GetDefautValue()
        {
            return DefaultValue;

        }
    }

    /// <summary>
    /// EString 数据类型
    /// </summary>
    public class EString : ExtendDataType
    {
        public static readonly EString DefaultValue = new EString ("");
        public static explicit operator bool(EString x) { return x.Value == DefaultValue.Value; }

        private string value;


        public EString() { this.value = DefaultValue.Value; }
        public EString(string value) { this.value = value; }

        #region 属性

        public string Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        public int Length { get { return this.value.Length; } }
        #endregion

        #region 方法
        public static implicit operator EString(string x) { return new EString(x); }
        public static explicit operator string(EString x) { return x.Value; }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        public static EString operator +(EString x, EString y) { return new EString(x.value + y.value); }
        public static bool operator ==(EString x, EString y) { return (x.value == y.value); }
        public static bool operator !=(EString x, EString y) { return (x.value != y.value); }
        #endregion

        #region
        public override System.Type ValueType { get { return typeof(string); } }
        /// <summary>
        /// string 类型
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (string)value; } }
        public override string StringValue
        {
            get { return this.value; }
            set { this.value = value; }
        }
        #endregion

        public override void SetValue(object value)
        {
            if (value == null)
                value = DefaultValue.Value;
            this.value = Convert.ToString(value);
        }

        protected EDTStringProperty property;
        public virtual EDTStringProperty Property { get; set; }
        public override EDTProperty BaseProperty
        {
            get
            {
                return this.Property;
            }
        }
        public override ExtendDataType  GetDefautValue()
        {
            return DefaultValue;

        }

    }

    /// <summary>
    ///EFloat数据类型 
    /// </summary>
    public class EFloat : ExtendDataType
    {
        private float value;
        public static readonly EFloat DefaultValue = new EFloat (0);
        public static explicit operator bool(EFloat x) { return x.Value == DefaultValue.Value; }



        public EFloat() { this.value = DefaultValue.Value; }
        public EFloat(float val) { this.value = val; }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        #region 属性

        public float Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region EFloat和float之间的显式转换
        public static implicit operator EFloat(float x) { return new EFloat(x); }
        public static explicit operator float(EFloat x) { return x.Value; }
        #endregion

        #region 运算符
        public static EFloat operator +(EFloat x) { return x; }
        public static EFloat operator -(EFloat x) { return (new EFloat(-x.value)); }

        public static EFloat operator +(EFloat x, EFloat y) { return new EFloat(x.value + y.value); }
        public static EFloat operator -(EFloat x, EFloat y) { return new EFloat(x.value - y.value); }
        public static EFloat operator *(EFloat x, EFloat y) { return new EFloat(x.value * y.value); }


        //EInt.Null可以和其他EInt 对象比较操作==,!=；
        public static bool operator ==(EFloat x, EFloat y) { return (x.value == y.value); }
        public static bool operator !=(EFloat x, EFloat y) { return (x.value != y.value); }
        public static bool operator >(EFloat x, EFloat y) { return (x.value > y.value); }
        public static bool operator <(EFloat x, EFloat y) { return (x.value < y.value); }
        public static bool operator >=(EFloat x, EFloat y) { return (x.value >= y.value); }
        public static bool operator <=(EFloat x, EFloat y) { return (x.value <= y.value); }
        #endregion


        #region 接口实现
        public override System.Type ValueType { get { return typeof(float); } }
        /// <summary>
        /// float 类型
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (float)value; } }
        public override string StringValue
        {
            get { return this.value.ToString(); }

            set { this.value = Convert.ToSingle(value); }
        }
        #endregion

        public override void SetValue(object value)
        {
            if (value == null)
                value = DefaultValue.Value;
            this.value = Convert.ToSingle(value);
        }
        public override ExtendDataType  GetDefautValue()
        {
            return DefaultValue;

        }
    }


    /// <summary>
    ///EDouble数据类型 
    /// </summary>
    public class EDouble : ExtendDataType
    {
        private double value;
        public static readonly EDouble DefaultValue = new EDouble (0.0);
        public static explicit operator bool(EDouble x) { return x.Value == DefaultValue.Value; }


        public EDouble() { this.value = DefaultValue.Value; }
        public EDouble(double val) { this.value = val; }

        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }

        #region 属性

        public double Value { get { return this.value; } set { this.value = value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region EDouble和double之间的显式转换
        public static implicit operator EDouble(double x) { return new EDouble(x); }
        public static explicit operator double(EDouble x) { return x.Value; }
        #endregion

        #region 运算符
        public static EDouble operator +(EDouble x) { return x; }
        public static EDouble operator -(EDouble x) { return (new EDouble(-x.value)); }

        public static EDouble operator +(EDouble x, EDouble y) { return new EDouble(x.value + y.value); }
        public static EDouble operator -(EDouble x, EDouble y) { return new EDouble(x.value - y.value); }
        public static EDouble operator *(EDouble x, EDouble y) { return new EDouble(x.value * y.value); }


        //EInt.Null可以和其他EInt 对象比较操作==,!=；
        public static bool operator ==(EDouble x, EDouble y) { return (x.value == y.value); }
        public static bool operator !=(EDouble x, EDouble y) { return (x.value != y.value); }
        public static bool operator >(EDouble x, EDouble y) { return (x.value > y.value); }
        public static bool operator <(EDouble x, EDouble y) { return (x.value < y.value); }
        public static bool operator >=(EDouble x, EDouble y) { return (x.value >= y.value); }
        public static bool operator <=(EDouble x, EDouble y) { return (x.value <= y.value); }
        #endregion


        #region 接口实现
        public override System.Type ValueType { get { return typeof(double); } }
        /// <summary>
        /// Double 类型
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (double)value; } }
        public override string StringValue
        {
            get { return this.value.ToString(); }
            set { this.value = Convert.ToDouble(value); }

        }
        #endregion

        public override void SetValue(object value)
        {
            if (value == null)
                value = DefaultValue.Value;
            this.value = Convert.ToDouble(value);
        }

        protected EDTRealProperty property;
        public virtual EDTRealProperty Property { get; set; }
        public override EDTProperty BaseProperty
        {
            get
            {
                return this.Property;
            }
        }
        public override ExtendDataType  GetDefautValue()
        {
            return DefaultValue;

        }

    }



    /// <summary>
    /// EDate类 日期
    /// </summary>
    public class EDate : ExtendDataType
    {
        public static readonly EDate DefaultValue =new EDate ( new DateTime(1900, 1, 1));
        public static explicit operator bool(EDate x) { return x.Value == DefaultValue.Value ; }

        private static int minYear = 1;
        private static int maxYear = 2500;
        private int year;
        private int month;
        private int day;


        #region 构造函数
        public EDate() { this.Value = DefaultValue.Value; }
        public EDate(int y, int m, int d)
        {

            if (ValidateDate(y, m, d))
            {
                this.year = y;
                this.month = m;
                this.day = d;
            }
        }
        public EDate(DateTime dTime) { this.day = dTime.Day; this.month = dTime.Month; this.year = dTime.Year; }
        #endregion

        #region 属性
        // public System.Type ControlType { get { return ((new DateTimePicker()).GetType()); } }
        public int DayOfYear { get { return (new DateTime(this.Year, this.Month, this.Day)).DayOfYear; } }

        public int Year { get { return this.year; } }
        public int Month { get { return this.month; } }
        public int Day { get { return this.day; } }
        public bool IsLeapyear { get { return (((this.Year % 4 == 0) && (this.Year % 100 != 0)) || ((this.Year % 100 == 0) && (this.Year % 400 == 0))); } }
        public DateTime Value { get { return (DateTime)(this); } set { this.ObjectValue = value; } }

        public string Date
        {
            get
            {
                string date = this.Year.ToString() + "-";
                if (this.Month < 10)
                    date = date + "0";
                date = date + this.Month.ToString() + "-";
                if (this.day < 10)
                    date = date + "0";
                date = date + this.Day.ToString();
                return date;
            }
            set
            {
                DateTime dTime = Convert.ToDateTime(value);
                this.year = dTime.Year;
                this.month = dTime.Month;
                this.day = dTime.Day;
            }
        }
        #endregion


        #region 验证函数
        //判断输入的年月日是否符合逻辑！
        public bool ValidateDate(int y, int m, int d)
        {
            bool result = (y >= minYear) && (y <= maxYear);
            result = result && (m >= 1) && (m <= 12);
            result = result && (d > 0);
            List<int> Days31 = new List<int>(new int[] { 1, 3, 5, 7, 8, 10, 12 });
            List<int> Days30 = new List<int>(new int[] { 4, 6, 9, 11 });

            if (Days31.Contains(m))
                return result && (d < 32);
            else if (Days30.Contains(m))
                return result && (d < 31);
            else if (m == 2)
                if (((y % 4 == 0) && (y % 100 != 0)) || ((y % 100 == 0) && (y % 400 == 0)))
                    return result && (d < 30);
                else
                    return result && (d < 29);
            if (!result)
                throw new InvalidTimeZoneException("你输入的日期超出范围！！");
            else
                return result;
        }
        #endregion

        #region 重载
        public override string ToString() { return this.StringValue; }
        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        #endregion

        #region 操作符以及转换
        public static implicit operator EDate(DateTime dTime) { return new EDate(dTime); }
        public static explicit operator DateTime(EDate tDate) { return new DateTime(tDate.Year, tDate.Month, tDate.Day); }

        public static bool operator ==(EDate x, EDate y) { return (x.Day == y.Day && x.Month == y.Month && x.Year == y.Year); }
        public static bool operator !=(EDate x, EDate y) { return (x.Day != y.Day || x.Month != y.Month || x.Year != y.Year); }
        public static bool operator >(EDate x, EDate y) { return ((x.Year > y.Year) || (x.Year == y.Year && x.Month > y.Month) || (x.Year == y.Year && x.Month == y.Month && x.Day > y.Day)); }
        public static bool operator <(EDate x, EDate y) { return ((x.Year < y.Year) || (x.Year == y.Year && x.Month < y.Month) || (x.Year == y.Year && x.Month == y.Month && x.Day < y.Day)); }
        public static bool operator >=(EDate x, EDate y) { return ((x.Year >= y.Year) || (x.Year == y.Year && x.Month >= y.Month) || (x.Year == y.Year && x.Month == y.Month && x.Day >= y.Day)); }
        public static bool operator <=(EDate x, EDate y) { return ((x.Year <= y.Year) || (x.Year == y.Year && x.Month <= y.Month) || (x.Year == y.Year && x.Month == y.Month && x.Day <= y.Day)); }

        public static int operator -(EDate x, EDate y) { return x.SubStract(y); }
        #endregion

        #region  DateTime属性
        public EDate AddDays(int days)
        {
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            dTime.AddDays(days);
            return (EDate)(dTime);
        }
        public EDate AddMonths(int months)
        {
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            dTime.AddMonths(months);
            return (EDate)(dTime);
        }
        public EDate AddYears(int years)
        {
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            dTime.AddYears(years);
            return (EDate)(dTime);
        }
        public int SubStract(EDate tDate)
        {
            TimeSpan tSpan = new TimeSpan();
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            tSpan = dTime.Subtract((DateTime)(tDate));
            return (int)(tSpan.TotalDays);
        }
        public EDate SubStract(int days)
        {
            DateTime dTime = new DateTime(this.Year, this.Month, this.Day);
            return (EDate)(dTime.Subtract(new TimeSpan(days, 0, 0, 0)));
        }
        #endregion


        #region
        public override System.Type ValueType { get { return typeof(DateTime); } }
        /// <summary>
        /// DateTime 类型 (EDate)
        /// </summary>
        public override object ObjectValue
        {
            get { return (DateTime)this; }
            set
            {
                this.year = ((DateTime)value).Year;
                this.month = ((DateTime)value).Month;
                this.day = ((DateTime)value).Day;
            }
        }
        public override string StringValue
        {
            get { return this.Date; }
            set { this.Date = value; }
        }
        #endregion

        public override void SetValue(object value)
        {
            if (value == null || value.ToString() == "")
                value = DefaultValue.Value;
            this.year = Convert.ToDateTime(value).Year;
            this.month = Convert.ToDateTime(value).Month;
            this.day = Convert.ToDateTime(value).Day;
        }

        protected EDTDateProperty property;
        public virtual EDTDateProperty Property { get; set; }
        public override EDTProperty BaseProperty
        {
            get
            {
                return this.Property;
            }
        }

        public override ExtendDataType  GetDefautValue()
        {
            return DefaultValue;

        }
    }

    /// <summary>
    /// ETime类 时间 24小时制
    /// </summary>
    public class ETime : ExtendDataType
    {
        public static readonly ETime  DefaultValue =new ETime (0);
        public static explicit operator bool(ETime x) { return x.Value == DefaultValue.Value; }

        public static ETime Null = new ETime();
        private int hour;
        private int minute;
        private int second;

        private int time;

        #region 构造函数
        public ETime() { this.TimeOffset = DefaultValue.Value; }
        public ETime(int x)
        {

            if (x >= 0)
            {
                int y = x % (60 * 60 * 24);
                this.hour = y / (60 * 60);
                this.minute = (y % (60 * 60)) / 60;
                this.second = (y % (60 * 60)) % 60;
            }
            else
            {
                throw new ArgumentException("输入参数太大或太小！");
            }

        }
        public ETime(int h, int m, int s)
        {

            if (ValidateTime(h, m, s))
            {
                this.hour = h; this.minute = m; this.second = s;
                time = h * 60 * 60 + m * 60 + s;
            }
        }
        public ETime(string timeString)
        {
            this.Time = timeString;
        }
        #endregion

        #region 验证函数
        public bool ValidateTime(int h, int m, int s)
        {
            bool result = (h >= 0 && h < 24) && (m >= 0 && m < 60) && (s >= 0 && s < 60);
            if (!result)
                throw new InvalidTimeZoneException("你输入的时间超出范围！！");
            else
                return result;
        }
        #endregion

        #region 属性

        public int Hour { get { return this.hour; } }
        public int Minute { get { return this.minute; } }
        public int Second { get { return this.second; } }
        //public System.Type ControlType { get { return ((new DateTimePicker()).GetType()); } }
        public int Value { get { return this.TimeOffset; } set { this.TimeOffset = value; } }
        public string Time
        {
            get
            {
                string time0 = "";
                if (this.hour < 10)
                    time0 += "0";
                time0 += this.hour.ToString() + ":";
                if (this.minute < 10)
                    time0 += "0";
                time0 += this.minute.ToString() + ":";
                if (this.second < 10)
                    time0 += "0";
                time0 += this.second.ToString();
                return time0;
            }
            set
            {

                string pattern = "[0-1][0-9]|2[0-3]:[0-5][0-9]:[0-5][0-9]";
                if (Regex.IsMatch(value, pattern))
                {
                    string timestring = value;
                    string[] time0 = timestring.Split(new char[] { ':' });
                    string hourString = time0[0];
                    string minuterString = time0[1];
                    string secondString = time0[2];
                    if (hourString == "00")
                        this.hour = 0;
                    else
                        this.hour = Convert.ToInt32(hourString.TrimStart(new char[] { '0' }));

                    if (minuterString == "00")
                        this.minute = 0;
                    else
                        this.minute = Convert.ToInt32(minuterString.TrimStart(new char[] { '0' }));

                    if (secondString == "00")
                        this.second = 0;
                    else
                        this.second = Convert.ToInt32(secondString.TrimStart(new char[] { '0' }));
                    this.time = this.Hour * 60 * 60 + this.Minute * 60 + this.second;

                }
                else
                {
                    throw new InvalidCastException("格式不正确，不能转换");
                }
            }
        }

        public int TimeOffset
        {
            get { return this.time; }
            set
            {
                int x = value;
                if (x >= 0)
                {
                    x = x % (60 * 60 * 24);
                    this.hour = x / (60 * 60);
                    this.minute = (x % (60 * 60)) / 60;
                    this.second = (x % (60 * 60)) % 60;
                }
                else
                {
                    throw new ArgumentException("输入参数太大或太小！");
                }

            }
        }
        #endregion

        #region 函数重载
        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }
        #endregion

        #region 操作符和类型转换
        public static implicit operator ETime(int x) { return new ETime(x); }
        public static explicit operator int(ETime tTime) { return tTime.TimeOffset; }//

        public static bool operator ==(ETime x, ETime y) { return (x.TimeOffset == y.TimeOffset); }
        public static bool operator !=(ETime x, ETime y) { return (x.TimeOffset != y.TimeOffset); }
        public static bool operator >(ETime x, ETime y) { return (x.TimeOffset > y.TimeOffset); }
        public static bool operator <(ETime x, ETime y) { return (x.TimeOffset < y.TimeOffset); }
        public static bool operator >=(ETime x, ETime y) { return (x.TimeOffset >= y.TimeOffset); }
        public static bool operator <=(ETime x, ETime y) { return (x.TimeOffset <= y.TimeOffset); }

        public static ETime operator -(ETime x, ETime y) { return new ETime(x.TimeOffset - y.TimeOffset); }
        #endregion

        #region ETime 方法
        public ETime AddSeconds(int seconds)
        {
            this.TimeOffset += seconds;
            this.TimeOffset = this.TimeOffset % (60 * 60 * 24);
            return this;
        }
        public ETime AddMinutes(int minutes)
        {
            this.TimeOffset += minutes * 60;
            this.TimeOffset = this.TimeOffset % (60 * 60 * 24);
            return this;
        }
        public ETime AddHours(int hours)
        {
            this.TimeOffset += hours * 60 * 60;
            this.TimeOffset = this.TimeOffset % (60 * 60 * 24);
            return this;
        }
        #endregion

        #region
        public override System.Type ValueType { get { return typeof(string); } }
        /// <summary>
        /// 用 int 类型的设置值
        /// </summary>
        public override object ObjectValue
        {
            get { return this.TimeOffset; }
            set
            {

                this.TimeOffset = (int)value;
            }
        }
        /// <summary>
        /// 格式：01:01:01
        /// </summary>
        public override string StringValue
        {
            get { return this.Time; }
            set { this.Time = value; }
        }
        #endregion


        protected EDTTimeProperty property;
        public virtual EDTTimeProperty Property { get; set; }
        public override EDTProperty BaseProperty
        {
            get
            {
                return this.Property;
            }
        }
        public override ExtendDataType  GetDefautValue()
        {
            return DefaultValue;

        }
        public override void SetValue(object value)
        {
            if (value == null)
                value = DefaultValue.Value;
            this.Value = Convert.ToInt32(value);
            //base.SetValue(value);
        }
    }


    /// <summary>
    /// EGuid类
    /// </summary>
    public class EGuid : ExtendDataType
    {

        private Guid value;


        #region 构造函数
        public EGuid() { }
        public EGuid(Guid value) { this.value = value; }
        #endregion

        #region 函数重载
        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }
        #endregion

        #region 属性

        public Guid Value { get { return this.value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region 操作符和类型转换
        public static implicit operator EGuid(Guid x) { return new EGuid(x); }
        public static explicit operator Guid(EGuid x) { return x.value; }
        //
        public static bool operator ==(EGuid x, EGuid y) { return (x.value == y.value); }
        public static bool operator !=(EGuid x, EGuid y) { return (x.value != y.value); }
        #endregion

        #region 接口实现
        public override System.Type ValueType { get { return typeof(Guid); } }
        /// <summary>
        /// Guid类型 EGuid
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (Guid)value; } }
        public override string StringValue { get { return this.value.ToString(); } set { this.value = new Guid(value); } }
        #endregion

        public override void SetValue(object value)
        {

            this.value = (Guid)value;
        }
    }

    /// <summary>
    /// EContainer类
    /// </summary>
    public class EContainer : ExtendDataType
    {
        public static readonly EContainer DefaultValue = new EContainer (new Container());
        public static explicit operator bool(EContainer x) { return x.Value == DefaultValue.Value; }


        private Container value;


        #region 构造函数
        public EContainer() { this.value = DefaultValue.Value; }
        public EContainer(Container value) { this.value = value; }
        #endregion

        #region 函数重载
        public override bool Equals(object obj) { return base.Equals(obj); }
        public override int GetHashCode() { return base.GetHashCode(); }
        public override string ToString() { return this.StringValue; }
        #endregion

        #region  属性

        public Container Value { get { return this.value; } }
        public string ValueString { get { return this.value.ToString(); } }

        public System.Type ControlType { get { return ((new ComboBox()).GetType()); } }
        #endregion

        #region 操作符和类型转换
        public static implicit operator EContainer(Container x) { return new EContainer(x); }
        public static explicit operator Container(EContainer x) { return x.value; }
        //
        public static bool operator ==(EContainer x, EContainer y) { return (x.value == y.value); }
        public static bool operator !=(EContainer x, EContainer y) { return (x.value != y.value); }
        #endregion

        #region 接口实现
        /// <summary>
        /// Container 类型 EContainer
        /// </summary>
        public override object ObjectValue { get { return this.value; } set { this.value = (Container)value; } }
        public override string StringValue { get { return this.ValueString; } set { this.value = null; } }
        public override System.Type ValueType { get { return typeof(Container); } }
        #endregion

        public override void SetValue(object value)
        {
            this.value = (Container)value;
        }

        protected EDTContainerProperty property;
        public virtual EDTContainerProperty Property { get; set; }
        public override EDTProperty BaseProperty
        {
            get
            {
                return this.Property;
            }
        }
        public override ExtendDataType  GetDefautValue()
        {
            return DefaultValue;

        }
    }

    

}

